Imports System.IO
Public Class ProgressBarDemo
    Dim count As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        ' Khai baùo vaø khôûi taïo ñoái töôïng DirectoryInfo
        Dim root As DirectoryInfo = New DirectoryInfo("C:\")
        Dim dirs As DirectoryInfo() = root.GetDirectories()
        ' Khai baùo thuoäc tính Maximum öùng vôùi soá löôïng thö muïc
        Me.ProgressBar1.Maximum = dirs.Length()
        Dim i As Integer = 0
        count = 0
        ' Duyeät qua töøng thö muïc
        For Each f As DirectoryInfo In dirs
            i = i + 1
            Me.ProgressBar1.Value = i
            ' Lieät keâ teân thö muïc treân Label1
            Me.Label1.Text = f.Name
            'Lieät keâ danh saùch taäp tin
            ReadFile(f.FullName)
        Next
        Me.Label1.Text = "Xong"
        Me.Text = String.Format("{0} folders {1} files", i, count)
    End Sub

    Private Sub ReadFile(ByVal foldername As String)
        Dim dir As New DirectoryInfo(foldername)
        Dim f As FileInfo
        For Each f In dir.GetFiles("*.*")
            count = count + 1
            Me.Text = f.Name
            Application.DoEvents()

        Next
    End Sub

End Class
